implémentation de tous les modes.
[minwii.git] / WiiMouse IR coeff0.1.PIE
1 Wiimote1.led1 = true
2 Wiimote2.led1 = true
3 Wiimote2.led4 = true
4 Wiimote3.led2 = true
5 Wiimote4.led2 = true
6 Wiimote4.led4 = true
7 Wiimote5.led3 = true
8 Wiimote6.led3 = true
9 Wiimote6.led4 = true
10 //Mouse Control Script using IR
11 //by vkapadia with much assistance from inio
12 //vkapadia@vkapadia.com
13 //
14 //Calibration:
15 //To calibrate, run this program and put the Wiimote on a flat surface face-up.
16 //Then read the values in the debug line (next to the run button).
17 //Change these values until the debug line reads approx. all zeros.
18 var.xtrim1 = -1
19 var.ytrim1 = -25
20 var.ztrim1 = 2
21
22 var.xtrim2 = -1
23 var.ytrim2 = -25
24 var.ztrim2 = 2
25
26 var.coeff = 0.1
27
28 //
29 //Options:
30 var.deadzone = 5 //distance in pixels that you have to move the wiimote in
31 //order for it to register movement. Creates a "dead zone" around the pointer
32 //to make it easier to click. Higher = smoother but less accurate.
33 //fake cursor init
34
35 //cursor2.visible = true
36
37 //more options to be added later
38
39 //Controls:
40 //Point Wiimote = Move Mouse
41 //D-Pad = Arrow Keys
42 //B-Button = Left Click
43 //Home = Middle Click
44 //A-Button = Right Click
45 //Plus and Minus = Control Volume
46 //One = Unmapped
47 //Two = Unmapped
48 //
49 //If the pointer hits the edge of the screen, the Wiimote will rumble a bit.
50 //
51 //The LEDs attempt to emulate KITT's grill from Knight Rider
52
53 //***Do not edit anything below this line unless you know what you are doing.***
54 var.accx1 = wiimote1.RawForceX1 + var.xtrim1
55 var.accy1 = wiimote1.RawForceY1 + var.ytrim1
56 var.accz1 = wiimote1.RawForceZ1 + var.ztrim1
57
58 if wiimote1.dot1vis and wiimote1.dot2vis then
59
60 if var.accy1 > -7 then
61 var.orientation1 = 0
62 elseif var.accy1 > -45 then
63 if var.accx1 < 0 then
64 var.orientation1 = 3
65 else
66 var.orientation1 = 1
67 endif
68 else
69 var.orientation1 = 2
70 endif
71
72 if var.leftpoint1 = 0 then
73 if var.orientation1 = 0 then
74 if wiimote1.dot1x < wiimote1.dot2x then
75 var.leftpoint1 = 1
76 else
77 var.leftpoint1 = 2
78 endif
79 endif
80 if var.orientation1 = 1 then
81 if wiimote1.dot1y > wiimote1.dot2y then
82 var.leftpoint1 = 1
83 else
84 var.leftpoint1 = 2
85 endif
86 endif
87 if var.orientation1 = 2 then
88 if wiimote1.dot1x > wiimote1.dot2x then
89 var.leftpoint1 = 1
90 else
91 var.leftpoint1 = 2
92 endif
93 endif
94 if var.orientation = 3 then
95 if wiimote1.dot1y < wiimote1.dot2y then
96 var.leftpoint1 = 1
97 else
98 var.leftpoint1 = 2
99 endif
100 endif
101 endif
102
103 if var.leftpoint1 = 1 then
104 var.fix1x1 = wiimote1.dot1x
105 var.fix1y1 = wiimote1.dot1y
106 var.fix2x1 = wiimote1.dot2x
107 var.fix2y1 = wiimote1.dot2y
108 else
109 var.fix1x1 = wiimote1.dot2x
110 var.fix1y1 = wiimote1.dot2y
111 var.fix2x1 = wiimote1.dot1x
112 var.fix2y1 = wiimote1.dot1y
113 endif
114
115 var.dx1 = var.fix2x1 - var.fix1x1
116 var.dy1 = var.fix2y1 - var.fix1y1
117 var.cx1 = (var.fix1x1+var.fix2x1)/1024.0 - 1
118 var.cy1 = (var.fix1y1+var.fix2y1)/1024.0 - .75
119
120 var.d1 = sqrt(var.dx1*var.dx1+var.dy1*var.dy1)
121
122 var.dx1 = var.dx1 / var.d1
123 var.dy1 = var.dy1 / var.d1
124
125 var.ox1 = -var.dy1*var.cy1-var.dx1*var.cx1;
126 var.oy1 = -var.dx1*var.cy1+var.dy1*var.cx1;
127
128 var.ax1 = (var.ox1 * var.coeff*screen.desktopwidth) + (screen.desktopwidth* var.coeff / 2)
129 var.ay1 = (-var.oy1* var.coeff * screen.desktopwidth) + (screen.desktopheight* var.coeff / 2)
130
131 var.dx1 = var.ax1 - cursor2.posx
132 var.dy1 = var.ay1 - cursor2.posy
133
134 var.d1 = sqrt((var.dx1*var.dx1)+(var.dy1*var.dy1))
135
136 var.a1 = 180 / (200 + var.d1 * var.d1 * var.d1 * .001)
137
138 if var.d1 <= var.deadzone then var.a1 = 1
139
140 //debug = var.d + " " + var.a
141
142 var.finalx1 = cursor2.posx * var.a1 + var.ax1 * (1 - var.a1)
143 var.finaly1 = cursor2.posy * var.a1 + var.ay1 * (1 - var.a1)
144
145
146 cursor2.posx = smooth(var.finalx1,3,5)
147 cursor2.posy = smooth(var.finaly1,3,5)
148
149 else
150
151 var.leftpoint1 = 0
152
153 endif
154
155 var.xpos1 = var.finalx1
156 var.ypos1 = var.finaly1
157 ppjoy1.analog0 = ensuremaprange(var.xpos1,0,screen.desktopwidth* var.coeff,-1,1)
158 ppjoy1.analog1 = ensuremaprange(var.ypos1,0,screen.desktopheight* var.coeff,-1,1)
159
160 if wiimote1.B or wiimote1.A or wiimote1.Up or wiimote1.down or wiimote1.Left or wiimote1.Right == true
161 ppjoy1.digital0 = true
162 else
163 ppjoy1.digital0 = false
164 endif
165
166 debug = var.accx1+ " " + var.accy1+ " " + var.accz1